package com.medicalproject.controller;


import com.medical.pojo.*;
import com.medical.vo.Rmed;
import com.medicalproject.service.Work_orderService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Random;

@RestController
@RequestMapping("/work-order")
//@CrossOrigin
public class Work_orderController {
    @Autowired
    private Work_orderService work_orderService;

    @RequestMapping("/findAll")
    public Rmed findAll(@RequestBody Work_order work_order){
        List<Work_order> list = work_orderService.findAll(work_order);
        return Rmed.suceessData(list);
    }

    @RequestMapping("/findById")
    public Rmed findById(Integer id){
        Work_order work_order = work_orderService.findById(id);
        return Rmed.suceessData(work_order);
    }

    @RequestMapping("/save")
    public Rmed save(@RequestBody Work_order work_order){
        if (work_order.getWorkOrderId()!=null){
            work_orderService.update(work_order);
        }else{
            work_order.setGdstatus(1);
            work_order.setWorkOrderNumber("WO"+new Random().nextInt(1000000000));
            work_order.setWorkOrderTime(LocalDateTime.now());
            work_order.setWorkOrderCreatetime(LocalDateTime.now());
            work_order.setWorkOrderChecktime(LocalDateTime.now());
            work_orderService.save(work_order);
        }
        return Rmed.suceessData(work_order);
    }

    @RequestMapping("/accessoryAll")
    public Rmed accessoryAll(){
        List<Accessory> accessoryList = work_orderService.accessoryAll();
        return Rmed.suceessData(accessoryList);
    }

    @RequestMapping("/accessoryById")
    public Rmed accessoryById(Integer id){
        Accessory accessory = work_orderService.accessoryById(id);
        return Rmed.suceessData(accessory);
    }

    @RequestMapping("/accessoryUpdate")
    public Rmed accessoryUpdate(@RequestBody Accessory accessory){
        work_orderService.accessoryUpdate(accessory);
        return Rmed.suceessData(accessory);
    }

    @RequestMapping("/accessoryjlAll")
    public Rmed accessoryjlAll(){
        List<Accessoryjl> accessoryList = work_orderService.accessoryjlAll();
        return Rmed.suceessData(accessoryList);
    }

    @RequestMapping("/accessoryjlById")
    public Rmed accessoryjlById(Integer id){
        Accessoryjl accessoryjl = work_orderService.accessoryjlById(id);
        return Rmed.suceessData(accessoryjl);
    }

    @RequestMapping("/accessoryjlSave")
    public Rmed accessoryjlSave(@RequestBody Accessoryjl accessoryjl){
        if (accessoryjl.getId()!=null){
            work_orderService.accessoryjlUpdate(accessoryjl);
        }else{
            work_orderService.accessoryjlSave(accessoryjl);
        }
        return Rmed.suceessData(accessoryjl);
    }

    @RequestMapping("/qcAll")
    public Rmed qcAll(){
        List<Qcjh> list = work_orderService.qcAll();
        return Rmed.suceessData(list);
    }

    @RequestMapping("/QcAll")
    public Rmed QcAll(){
        List<Qc> list = work_orderService.QcAll();
        return Rmed.suceessData(list);
    }

    @RequestMapping("/qcById")
    public Rmed qcById(Integer id){
        Qc qcjh = work_orderService.qcById(id);
        return Rmed.suceessData(qcjh);
    }

    @RequestMapping("/smqzAll")
    public Rmed smqzAll(){
        List<Smzq> list = work_orderService.smqzAll();
        return Rmed.suceessData(list);
    }

    @RequestMapping("/gdrzAll")
    public Rmed gdrzAll(){
        List<Gdrz> list = work_orderService.gdrzAll();
        return Rmed.suceessData(list);
    }

    @RequestMapping("/wbdwAll")
    public Rmed wbdwAll(){
        List<Wbdw> list = work_orderService.wbdwAll();
        return Rmed.suceessData(list);
    }

    @RequestMapping("/xjdwAll")
    public Rmed xjdwAll(){
        List<Xjdw> list = work_orderService.xjdwAll();
        return Rmed.suceessData(list);
    }
}
